package com.carreirati.evaluation;

import java.util.List;

import com.carreirati.evaluation.domain.AppraisalRelationship;
import com.carreirati.evaluation.domain.AppraisalResults;
import com.carreirati.evaluation.domain.KnowledgeArea;
import com.carreirati.evaluation.domain.Parameter;
import com.carreirati.evaluation.domain.Question;
import com.carreirati.evaluation.domain.QuestionParameter;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.roo.addon.web.mvc.controller.json.RooWebJson;
import org.springframework.roo.addon.web.mvc.controller.scaffold.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/questions")
@Controller
@RooWebScaffold(path = "questions", formBackingObject = Question.class)
@RooWebJson(jsonObject = Question.class)
public class QuestionController {
	
	 void populateEditForm(Model uiModel, Question question) {
	        uiModel.addAttribute("question", question);
	        uiModel.addAttribute("appraisalrelationships", AppraisalRelationship.findAllAppraisalRelationships());
	        uiModel.addAttribute("appraisalresultses", AppraisalResults.findAllAppraisalResultses());
	        uiModel.addAttribute("knowledgeareas", KnowledgeArea.findAllKnowledgeAreas());
	        uiModel.addAttribute("questionparameters", QuestionParameter.findAllQuestionParameters());
	        uiModel.addAttribute("parameters", Parameter.findAllParameters());
	    }
	 
	    @RequestMapping(value = "/getquestionnotinappraisal{appraisalId}", headers = "Accept=application/json")
	    @ResponseBody
	    public ResponseEntity<java.lang.String> getQuestionNotInAppraisalJson(@PathVariable("appraisalId") long appraisalId) {
	        HttpHeaders headers = new HttpHeaders();
	        headers.add("Content-Type", "application/json; charset=utf-8");
	        List<Question> result = Question.findQuestionsNotInAppraisal(appraisalId);
	        return new ResponseEntity<String>(Question.toJsonArray(result), headers, HttpStatus.OK);
	    }
}
